package com.yz.bi.manager;

import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.core.auth.Auth;
import com.baidubce.qianfan.model.chat.ChatResponse;
import com.baidubce.qianfan.model.completion.CompletionResponse;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
import org.json.JSONObject;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * Created With IntelliJ IDEA.
 * Descriptions:
 * <p>
 * User:Mr.Du
 * Date:2024/6/22
 * Time:17:30
 */
@Slf4j
@Service
public class BdManager {

    public static final String API_KEY = "your api_key";
    public static final String SECRET_KEY = "your_secret_key";
    static final OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().build();

    public String doChat(String s1, String s2){
        Qianfan qianfan = new Qianfan(Auth.TYPE_OAUTH, API_KEY, SECRET_KEY);
        String s = "xxxxx";
        String formatted = String.format(s, s1, s2);
        ChatResponse response = qianfan.chatCompletion()
                .model("ERNIE-Bot-4")
                .addMessage("user", formatted)
                .temperature(0.7)
                .execute();
        String json = response.getResult().replace("json", "").trim();
        return json;
    }
}
